from wormbane.model.corpse import Corpse
from wormbane.model.monster import Monster
from wormbane.util.decorators import classproperty

class Race(object):
    color = None
    health = 1
    size = 'medium'
    frequency = 1.0

    slots = {'amulet': 1, 'armor': 1, 'belt': 1, 'boots': 1, 'cloak': 1,
             'gloves': 1, 'helm': 1, 'ring': 2, 'shield': 1, 'shirt': 1,
             'weapon': 1}
    top_slots = ('cloak', 'armor', 'shirt')

    @classproperty
    def name(cls):
        result = cls.__name__.lower()
        cls.name = result
        return result

    @classproperty
    def char(cls):
        result = cls.name[0]
        if cls.size in ('large', 'huge'):
            result = result.upper()
        cls.char = result
        return result

    @classmethod
    def create_corpse(cls, monster = None):
        return Corpse(race = cls)

    @classmethod
    def create_equipment(cls):
        return []

    @classmethod
    def create_treasure(cls):
        return []

    @classmethod
    def create_monster(cls):
        return Monster(race = cls)

    @classmethod
    def create_equipped_monster(cls):
        monster = cls.create_monster()
        for item in reversed(list(cls.create_equipment())):
            item.move_to(monster)
            try:
                if item.is_weapon:
                    monster.wield(item)
                elif item.is_armor:
                    monster.wear(item)
            except:
                pass
        return monster
